﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace STS.Pacjent
{
    public partial class wybierz : System.Web.UI.Page
    {
        
        baza db = new baza();
        protected void Page_Load(object sender, EventArgs e)
        {
            DetailsView1.Visible = false;
            Main.idpacjenta = 0;
            Master.FindControl("NavigationMenuR").Visible = false;
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            Main.idpacjenta = Convert.ToInt32(DropDownList1.SelectedValue);
            DetailsView1.Visible = true;

            string strConnection = "Data Source=BZYLAK-DELL;Initial Catalog=MGR;Integrated Security=True";
            SqlConnection sqlConnection = new SqlConnection(strConnection);
            String SQLQuery = "SELECT stan FROM dane_pacjentow where ID_pacjenta=" + DropDownList1.SelectedValue;
            SqlCommand command = new SqlCommand(SQLQuery, sqlConnection);
            SqlDataReader Dr;
            sqlConnection.Open();
            Dr = command.ExecuteReader();
            Dr.Read();
            int stan = Convert.ToInt32(Dr["stan"].ToString());
            Dr.Close();

            if (stan == 0)
            {
                Label1.Text = "nie zakwalifikowany do przeszczepu";
            }
            if (stan == 1)
            {
                Label1.Text = "zakwalifikowany do przeszczepu";
            }
            if (stan == 2)
            {
                Label1.Text = "po przeszczepie";
            }
            Label1.Visible = true;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            
           // Button3.Visible = true;
            Button4.Visible = true;
            Button5.Visible = true;
            Button6.Visible = true;

        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            var ud = db.dane_pacjentows.SingleOrDefault(fbu => fbu.id_pacjenta == Convert.ToInt32(DropDownList1.SelectedValue));
            ud.stan = 0;
            db.SubmitChanges();
            Label1.Text = "nie zakwalifikowany do przeszczepu";
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            var ud = db.dane_pacjentows.SingleOrDefault(fbu => fbu.id_pacjenta == Convert.ToInt32(DropDownList1.SelectedValue));
            ud.stan = 2;
            db.SubmitChanges();
            Label1.Text = "po przeszczepie";
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            var ud = db.dane_pacjentows.SingleOrDefault(fbu => fbu.id_pacjenta == Convert.ToInt32(DropDownList1.SelectedValue));
            ud.stan = 1;
            Label1.Text = "zakwalifikowany do przeszczepu";
            db.SubmitChanges();
        }
    }
}